package com.net.wanjian.networkhospitalmanager.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.net.wanjian.networkhospitalmanager.R;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

/**
 * Description:
 * Created by lidongcai on 17/7/24.
 * Email:  lidongcaiocc@163.com
 */

public class RotateYearAdapter extends BaseAdapter {
    private List<String> yearStringList;
    private Context mContext;
    //        一级联动选中的位置
    private int selectedPosition = 2;

    public RotateYearAdapter(Context mContext,List<String> yearStringList) {
        this.yearStringList = yearStringList;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return yearStringList == null ? 0 :yearStringList.size();
    }

    @Override
    public Object getItem(int position) {
        return yearStringList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder  holder;
        if (convertView == null){
            View view = LayoutInflater.from(mContext).inflate(R.layout.item_pop_window_rotate_year, parent, false);
            AutoUtils.auto(view);
            convertView = view;
            holder = new ViewHolder();
            holder.textView = (TextView) convertView.findViewById(R.id.item_pop_window_rotate_year_tv);
            holder.imageView = (ImageView) convertView.findViewById(R.id.item_pop_window_rotate_year_iv);
            convertView.setTag(holder);

        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.textView.setText(yearStringList.get(position)+"年");

        //选中和没选中时，设置不同的颜色
        if (position == selectedPosition) {
            holder.textView.setTextColor(mContext.getResources().getColor(R.color.colorMain));
            holder.imageView.setVisibility(View.VISIBLE);
        }else {
            holder.textView.setTextColor(mContext.getResources().getColor(R.color.color_text_black));
            holder.imageView.setVisibility(View.GONE);
        }


        return convertView;
    }

    public void setSelectedPosition(int selectedPosition) {
        this.selectedPosition = selectedPosition;
    }

    static class ViewHolder{
        TextView textView;
        ImageView imageView;
    }
}
